<%@ page language="java"  pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>系统管理</title>
<link href="<%=path%>/styles/main.css" rel="stylesheet" type="text/css" />
<link href="<%=path %>/js/jtree/css/tree.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" id='skin' type="text/css" href="<%=path %>/js/dialog/skin/ymPrompt.css" /> 
 
<script type="text/javascript" src="<%=path%>/js/main.js"></script>
<script src="<%=path %>/js/jquery-1.4.2.min.js" type="text/javascript"></script>
<script src="<%=path %>/js/jtree/tree.js" type="text/javascript" ></script> 
<script src="<%=path %>/js/dialog/ymPrompt.js" type="text/javascript" ></script>
<script type="text/javascript">
var topMenuIndex=1;
var menuIndex=6; 
</script>
</head>
<body>
<%@ include file="../common/Header.jsp"%>
<%@ include file="Menu.jsp"%>
<form method="post">
<div id="Content">
   <div id="mainLeftLayout" >
	  	<h1 class="title"><span>权限资源树导航</span></h1>
		<div class="innerLinemain" style="height:380px; padding:4px;">
			<div id="tree"></div>	     
		</div>		
   </div> 

   <div id="mainRightLayout" >
  		<h1 class="title"><span>机构详细信息</span></h1>
		<div class="innerLinemain" style="height:380px; padding:4px;">
			<table width="100%" border="0" cellspacing="2" cellpadding="0" align="center"  class="TableForm">
				  <tr >
					<td width="58" nowrap="nowrap">资源名称<span class="redMst">*</span></td>
					<td width="648" >
						<input name="resId" type="hidden" /><input name="resPid" type="hidden"/>
						<input name="resName" type="text" class="InputText" onfocus="this.className='InputTextDown'" onblur="this.className='InputText'" />
					</td>
				  </tr>		  
				  <tr >
					<td nowrap="nowrap">资源路径<span class="redMst">*</span></td>
					<td>					
						<input name="resPath" type="text" class="InputText" onfocus="this.className='InputTextDown'" onblur="this.className='InputText'" />
					</td>
				  </tr>
				  <tr >
					<td nowrap="nowrap">资源类型<span class="redMst">*</span></td>
					<td>					
						<input name="resType" type="text" class="InputText" onfocus="this.className='InputTextDown'" onblur="this.className='InputText'" />
					</td>
				  </tr>			
				  <tr>
					<td  nowrap="nowrap" >资源描述<span class="redMst">*</span></td>
					<td ><textarea name="resDesc" rows="10" class="InputText" onfocus="this.className='InputTextDown'" onblur="this.className='InputText'"></textarea> </td>	
				  </tr>     
			</table>
		</div>	
  </div> 

  <div id="FormToobar" class="clear">	
		<tt><input class="But" type="button" id="btnAdd" value="增加" onclick="add()" /></tt>
		<tt><input class="But" type="button" id="btnUpd" value="修改" onclick="upd()" /></tt>
		<tt><input class="But" type="button" id="btnDel" value="删除" onclick="del()"/></tt>      
        <tt><input class="But_disabled" type="button" id="btnSave" value="保存" onclick="save()" /></tt> 
        <tt><input class="But_disabled" type="button" id="btnCancle" value="取消" onclick="cancle()"/></tt> 
  </div>
</div>
</form> 
<script type="text/javascript">
  	  var treedata=[{ "id": "0", "text": "知识库管理系统", "value": "11", "showcheck": true, "isexpand": false, "checkstate": 0, "hasChildren": true, "ChildNodes": null, "complete": false }];
      var userAgent = window.navigator.userAgent.toLowerCase();
      $.browser.msie8 = $.browser.msie && /msie 8\.0/i.test(userAgent);
      $.browser.msie7 = $.browser.msie && /msie 7\.0/i.test(userAgent);
      $.browser.msie6 = !$.browser.msie8 && !$.browser.msie7 && $.browser.msie && /msie 6\.0/i.test(userAgent);
      function load() {        
          var o = {
          	showcheck: false,
          	onnodeclick:function(item){view(item.id);},          
          	url: "<%=path %>/system/resource/listTree.do",
          	imagepath:"<%=path %>/js/jtree/images/"          	
          };
          o.data = treedata; 
          $("#tree").treeview(o); 
      }      
      //查看
      function view(id){
      	$.get("<%=path %>/system/resource/load.do",{id:id},
      		  function(data){
      		  	document.forms[0]["resId"].value=data.resId;
      		  	document.forms[0]["resPid"].value=data.resPid;
      		  	document.forms[0]["resName"].value=data.resName;
      		  	document.forms[0]["resPath"].value=data.resPath;
      		  	document.forms[0]["resType"].value=data.resType;
      		  	document.forms[0]["resDesc"].value=data.resDesc;
      		  	showBtn(true,true,true,false,false);
      		  },"json");
      } 
      //保存 
      var operation; 
      function save(){      
      	$.post("<%=path %>/system/resource/save.do",
      		  {resId:document.forms[0]["resId"].value,
      		   resPid:document.forms[0]["resPid"].value,
      		   resName:document.forms[0]["resName"].value,
      		   resPath:document.forms[0]["resPath"].value,
      		   resType:document.forms[0]["resType"].value,
      		   resDesc:document.forms[0]["resDesc"].value,
      		   operation:operation
      		  },
      		  function(data){
      		  	var s=$("#tree").getTCT();  
      		  	if(data=="add"){      		    
	               	$("#tree").refresh(s.id);
	               	showBtn(true,true,true,false,false);
	               	clearForm();
	               	ymPrompt.succeedInfo({title:'提示信息',message:'添加成功！'}); 
	               	operation="update";
               	}else if(data=="update"){
               		$("#tree").refresh(s.pid);
               		showBtn(true,true,true,false,false);
               		clearForm();
               		ymPrompt.succeedInfo({title:'提示信息',message:'修改成功！'});  
               		operation="update";
               	}else{
               		ymPrompt.erroInfo({title:'提示信息',message:'保存失败！'});  
               	}
      		  },"string");
      }   
	  //增加
	  function add(){
	  	if(check()){
		  	operation="add";
		  	document.forms[0]["resName"].value="";
		  	document.forms[0]["resPath"].value="";
		  	document.forms[0]["resType"].value="";
	      	document.forms[0]["resDesc"].value="";
		  	showBtn(false,false,false,true,true);
	  	}
	  }
	   //修改
	  function upd(){
	  	if(check()){
		  	operation="update";
		  	showBtn(false,false,false,true,true);
	  	}
	  }
	  //取消
	  function cancle(){
	 	operation="update";
	  	showBtn(true,true,true,false,false);
	  }
	  //删除
	  function del(){
	  	if(check()){
	  		var s=$("#tree").getTCT();
		  	$.post("<%=path %>/system/resource/del.do",
	      		  {id:s.id},
	      		   function(data){      		 
	      		  	if(data=="delete"){
		               	$("#tree").refresh(s.pid);
		                clearForm();
		               	ymPrompt.succeedInfo({title:'提示信息',message:'删除成功！'});	               	
	               	}else if(data=="exist"){	
	               		ymPrompt.alert({title:'提示信息',message:'存在下级资源，不能删除！'});               	
	               	}else{
	               		ymPrompt.errorInfo({title:'提示信息',message:'操作失败！'});	             
	               	}
	      		  },"string");
      	}
	  }
	  function check(){
	  	var s=$("#tree").getTCT(); 
	  	var id=document.forms[0]["resId"].value;
	  	if(s==undefined || id=="" || id==null){
	  		ymPrompt.alert({title:'提示信息',message:'请选择您要操作的资源！'});
	  		return false;
	  	}
	  	return true;
	  }
	  //清空表单
	  function clearForm(){
		  	document.forms[0]["resId"].value="";
	       	document.forms[0]["resPid"].value="";
	       	document.forms[0]["resName"].value="";
	       	document.forms[0]["resPath"].value="";
	       	document.forms[0]["resType"].value="";
			document.forms[0]["resDesc"].value="";
	  }
	  //控制按钮的显示
	  function showBtn(pAdd,pDel,pUpd,pSave,pCancle){
	  	if(pAdd){
	  		document.getElementById("btnAdd").className="But";
	  		document.getElementById("btnAdd").disabled=false;
	  	}else{
	  		document.getElementById("btnAdd").className="But_disabled";
	  		document.getElementById("btnAdd").disabled=true;
	  	}	  	
	  	if(pDel){
	  		document.getElementById("btnDel").className="But";
	  		document.getElementById("btnDel").disabled=false;
	  	}else{
	  		document.getElementById("btnDel").className="But_disabled";
	  		document.getElementById("btnDel").disabled=true;
	  	}	  	
	  	if(pUpd){
	  		document.getElementById("btnUpd").className="But";
	  		document.getElementById("btnUpd").disabled=false;
	  	}else{
	  		document.getElementById("btnUpd").className="But_disabled";
	  		document.getElementById("btnUpd").disabled=true;
	  	}	  	
	  	if(pSave){
	  		document.getElementById("btnSave").className="But";
	  		document.getElementById("btnSave").disabled=false;
	  	}else{
	  		document.getElementById("btnSave").className="But_disabled";
	  		document.getElementById("btnSave").disabled=true;
	  	}
	  	if(pCancle){
	  		document.getElementById("btnCancle").className="But";
	  		document.getElementById("btnCancle").disabled=false;
	  	}else{
	  		document.getElementById("btnCancle").className="But_disabled";
	  		document.getElementById("btnCancle").disabled=true;
	  	}
	  }	  
      //加载树
      if( $.browser.msie6){load();}else{$(document).ready(load);}      
  </script> 
</body>
</html>
